package net.awpspace.mobile.management.contact;



import net.awpspace.mobile.management.contact.Contact;

import java.util.Vector;

public class Datafull {
	private Vector datafull;
	
	private static Datafull instance;
	
	private Datafull(){
		datafull = new Vector();
		createConstance();
	}
	
	public static Datafull getInstance(){
		if(instance == null)
			instance = new Datafull();
		return instance;
	}
	
	public void add(Contact ct){
		datafull.addElement(ct);
	}
	public Vector getDatafull(){
		return datafull;
	}
	public void delete(int i){
		if(i < 0 || i >= datafull.size())
			return;
		datafull.removeElementAt(i);
	}
	public void detele(Contact ct){
		datafull.removeElement(ct);
	}
	public void createConstance(){
		/*
		 * Tạo dữ liệu tĩnh
		 */
		add(new Contact("Nguyễn Tiến Mạnh","Bắc Giang", "a@yahoo.com", "12345678"));
		add(new Contact("Nguyễn Tuấn Hải","Bắc Giang","a@yahoo.com", "12345678"));
		add(new Contact("Nguyễn Hoàng Điệp","Bắc Giang","a@yahoo.com", "12345678"));
		add(new Contact("Nguyễn Thị Kim","Bắc Giang","a@yahoo.com", "12345678"));
		add(new Contact("Phạm Hồng kỳ","Bắc Giang","a@yahoo.com", "12345678"));
	}

	public void update(Contact contact) {
		// TODO Auto-generated method stub
		int index = -1;
		for(int i = 0; i < datafull.size(); i++){
			if(contact.getTen().equals(((Contact)datafull.elementAt(i)).getTen())){
				index = i;
				datafull.removeElementAt(index);
				datafull.insertElementAt(contact, index);
				return;
			}
		}
	}

}
